home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 919 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: tangaroa@werple.net.au (Simon Crase)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Const class member
  5. Date: 31 Mar 1996 02:20:21 GMT
  6. Organization: Werple Internet, Melbourne
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4jkjuq$t4h@eplet.mira.net.au>
  9. References: <4jgpqa$t09@nntp.interaccess.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. X-Nntp-Posting-Host: werplez.mira.net.au
  12. X-Newsreader: TIN [version 1.2 PL2]
  13. Content-Length: 1840
  14. Originator: clamage@taumet
  15.  
  16. Brian V. McGroarty (brianmcg@interaccess.com) wrote:
  17. : Is this legal?  Borland and Microsoft compilers will accept the following:
  18.  
  19. : class AnyClass
  20. : {
  21. :     const int constInt;
  22. : }
  23.  
  24. : The Borland compiler complains about the uninitialized constant, whereas
  25. : the Microsoft compiler does not.  If a constructor is present, both will
  26. : complain that the constant isn't initialized in the constructor, however
  27. : neither will allow you to assign a value in the constructor by simply
  28. : specifying "constInt= some value".  I have also attempted to initialize in
  29. Have you tried:
  30. AnyClass::AnyClass
  31.     : constInt(42)
  32. {
  33. }
  34. The geenral idea seems to be to disallow any piece of code that assigns
  35. a value using constInt=....
  36. : a global variable "int AnyClass::constInt",  to determine whether static
  37. : somehow became implicit -- still no go.  If this is legal, how is the value
  38. : initialized?
  39.  
  40. : Would compilers stand a better chance of optimizing given the above via
  41. : constant propogation through inlined (member only?) functions applied to a
  42. : hard-coded instance of the object, or would it just be to help prevent
  43. : programmers' error?
  44.  
  45. : ---
  46. : Brian Valters McGroarty -- brianmcg@bix.com
  47. : phone/fax (847) 439-7714
  48. : ---
  49. : [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  50. : [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  51. : [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  52. : [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  53. : [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  54.  
  55. --
  56. Simon A. Crase         Emerson & Crase Consultants - ++61-3-9592-1764
  57. Artificial Intelligence, Graphical User Interfaces, C++,
  58. Object Oriented Design, Microsoft Windows Applications
  59. s.crase@ieee.org = tangaroa@werple.net.au
  60.  
  61.  
  62. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  63. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  64. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  65. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  66. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  67.